function ajax(url, type, data, contentType, callback) {
    contentType = !isEmpty(contentType) ? (contentType.indexOf("json") !== -1 ? "application/json" : contentType) : "application/x-www-form-urlencoded";
    let authToken = localStorage.getItem("Authorization");
    $.ajax({
        url: url,
        type: type,
        data: contentType.endsWith("json") ? JSON.stringify(data) : data,
        contentType: contentType,
        headers: {
            Authorization: authToken
        },
        success: isEmpty(callback) ? (ret) => {
            console.log(ret);
            document.write(ret);
        } : callback
    });

}

function isEmpty(obj) {
    return obj === undefined || obj === null || obj === "";
}